import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;

class Student {
    public String id;

    public Student(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class Test {
    public static void main4(String[] args) {
        Student student1 = new Student("1234");
        Student student2 = new Student("1234");

        HashBuck2<Student,String> hashBuck2 = new HashBuck2<>();
        hashBuck2.put(student1,"xiaoming");

        System.out.println(hashBuck2.getVal(student2));
    }
    public static void main3(String[] args) {
        //找到这组数据中第一个重复的数据
        int[] array = {1,2,3,4,4,5,6,8,9,1,2,7,5,20,10,4,20,6};
        HashSet<Integer> hashSet = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            if (!hashSet.contains(array[i])) {
                hashSet.add(array[i]);
            }else {
                System.out.println(array[i]);
                return;
            }
        }
    }
    public static void main2(String[] args) {
        // HashMap 和 HashSet 具有天然的去重效果
        int[] array = {1,2,3,4,4,5,6,8,9,1,2,7,5,20,10,4,20,6};
        HashSet<Integer> hashSet = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            hashSet.add(array[i]);
        }
        System.out.println(hashSet);
    }
    public static void main1(String[] args) {
        HashMap<String,Integer> hashMap = new HashMap();
        hashMap.put("abc",3);
        hashMap.put("hello",10);
        hashMap.put("world",5);
        System.out.println(hashMap);

        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("abc");
        hashSet.add("hello");
        hashSet.add("world");
        System.out.println(hashSet);

        //放入的数据不需要进行比较，也就是不需要一定实现 Comparable 接口
        HashMap<Student,Integer> hashMap2 = new HashMap<>();
        hashMap2.put(new Student("123"),3);
        hashMap2.put(new Student("456"),5);

    }
}
